package com.woniu.communitymanagement.service.impl;


import com.woniu.communitymanagement.entity.HttpResult;
import com.woniu.communitymanagement.entity.Owner;
import com.woniu.communitymanagement.entity.Repair;
import com.woniu.communitymanagement.entity.RepairType;
import com.woniu.communitymanagement.service.RepairService;
import com.woniu.communitymanagement.mapper.RepairMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 14542
* @description 针对表【repair(报修信息管理表)】的数据库操作Service实现
* @createDate 2022-11-30 18:55:35
*/
@Service
public class RepairServiceImpl implements RepairService{
    @Autowired(required = false)
    private RepairMapper repairMapper;

    @Override
    public HttpResult insertRepair(Repair repair){
        HttpResult httpResult=null;
        int count = repairMapper.insertRepair(repair);
        if(count>0){
            httpResult=new HttpResult(null,null,200,"添加成功");
        }else{
            httpResult=new HttpResult(null,null,500,"添加失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult deleteRepairById(int id) {
        HttpResult httpResult=null;
        int count = repairMapper.deleteRepair(id);
        if(count>0){
            httpResult=new HttpResult(null,null,200,"删除成功");
        }else{
            httpResult=new HttpResult(null,null,500,"删除失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult updateRepairById(int id) {
        HttpResult httpResult=null;
        int count = repairMapper.updateRepair(id);
        if(count>0){
            httpResult=new HttpResult(null,null,200,"修改成功");
        }else{
            httpResult=new HttpResult(null,null,500,"修改失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult refreshRepairById(int id) {
        HttpResult httpResult=null;
        int count = repairMapper.refresh(id);
        if(count>0){
            httpResult=new HttpResult(null,null,200,"修改成功");
        }else{
            httpResult=new HttpResult(null,null,500,"修改失败");
        }
        return httpResult;
    }


    @Override
    public HttpResult selectRepairAll(String comId,String status,int pageIndex,int pageSize) {
        HttpResult httpResult=null;
        int start = (pageIndex-1)*pageSize;
         List<Repair> repairs = repairMapper.selectRepairList(comId,status,start,pageSize);
        Integer count = repairMapper.selectCount(comId, status);
        if(repairs!=null&&repairs.size()>0){
            httpResult=new HttpResult(repairs,count,200,"查询成功");
        }else {
            httpResult=new HttpResult(null,null,500,"查询失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult selectRepairById(int id) {
        HttpResult httpResult=null;
        Repair repair = repairMapper.selectRepairById(id);
        if(repair!=null){
            httpResult=new HttpResult(repair,1,200,"查询成功");
        }else{
            httpResult=new HttpResult(null,null,500,"查询失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult selectRepairTypeAll() {
        HttpResult httpResult=null;
        List<RepairType> repairTypes = repairMapper.selectRepairType();
        if(repairTypes!=null){
            httpResult=new HttpResult(repairTypes,1,200,"查询成功");
        }else{
            httpResult=new HttpResult(null,null,500,"查询失败");
        }
        return httpResult;
    }

    @Override
    public HttpResult selectOwnerAll() {
        HttpResult httpResult=null;
        List<Owner> owners = repairMapper.selectOwner();
        if(owners!=null){
            httpResult=new HttpResult(owners,1,200,"查询成功");
        }else{
            httpResult=new HttpResult(null,null,500,"查询失败");
        }
        return httpResult;
    }

}




